#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

class Solution {
public:
  int minAddToMakeValid(string s) {
    int tmp = 0;
    int res = 0;
    for (auto p = s.begin(); p != s.end(); ++p) {
      if (*p == ')') {
        --tmp;
        if (tmp < 0) {
          ++res;
          ++tmp;
        }
      } else {
        ++tmp;
      }
    }
    if (tmp > 0) {
      res += tmp;
    }
    return res;
  }
};

int main(int argc, char *argv[]) {
  string a = "())";
  Solution s;
  cout<<s.minAddToMakeValid(a);

  return 0;
}
